<!Doctype html>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
	<meta name="viewport" content="width=device-width, initial-scale=1.0" />
	<title>7.0 Zookeeper 客户端基础命令使用 | 菜鸟教程</title>

  <meta name='robots' content='max-image-preview:large' />
<link rel='stylesheet' id='classic-theme-styles-css' href='../0/classic-themes.min.css?ver=6.2' type='text/css' media='all' />
<link rel="canonical" href="../w3cnote/zookeeper-bs-command.html" />
<meta name="keywords" content="7.0 Zookeeper 客户端基础命令使用">
<meta name="description" content="zookeeper 命令用于在 zookeeper 服务上执行操作。首先执行命令，打开新的 session 会话，进入终端。 $ sh zkCli.sh 下面开始讲解基本常用命令使用，其中 acl 权限内容在后面章节详细阐述。 ls 命令 ls 命令用于查看某个路径下目录列表。 格式：ls path  path：代表路径。  以下实例查看 /runoob 节点： $ ls /runoob   ls2 命令 ls2 命令用于查看某个路径下..">
		
	<link rel="shortcut icon" href="https://static.runoob.com/images/favicon.ico">
	<link rel="stylesheet" href="../0/style.css?v=1.170" type="text/css" media="all" />	
	<link rel="stylesheet" href="../0/font-awesome.min.css" media="all" />	
  <!--[if gte IE 9]><!-->
  <script src=""></script>
  <!--<![endif]-->
  <!--[if lt IE 9]>
     <script src=""></script>
     <script src=""></script>
  <![endif]-->
  <link rel="apple-touch-icon" href="https://static.runoob.com/images/icon/mobile-icon.png"/>
  <meta name="apple-mobile-web-app-title" content="菜鸟教程">
</head>
<body>

<!--  头部 -->
<div class="container logo-search">

  <div class="col search row-search-mobile">
    <form action="index.php">
      <input class="placeholder" placeholder="搜索……" name="s" autocomplete="off">
      
    </form>
  </div>

  <div class="row">
    <div class="col logo">
      <h1><a href="../">菜鸟教程 -- 学的不仅是技术，更是梦想！</a></h1>
    </div>
        <div class="col right-list"> 
    <button class="btn btn-responsive-nav btn-inverse" data-toggle="collapse" data-target=".nav-main-collapse" id="pull" style=""> <i class="fa fa-navicon"></i> </button>
    </div>
        
    <div class="col search search-desktop last">
      <div class="search-input" >
      <form action="//www.runoob.com/" target="_blank">
        <input class="placeholder" id="s" name="s" placeholder="搜索……"  autocomplete="off" style="height: 44px;">
      </form>
      
      </div>
    </div>
  </div>
</div>



<!-- 导航栏 -->
<div class="container navigation">
    <div class="row">
        <div class="col nav">
            

                        <ul class="pc-nav" id="note-nav">
                <li><a href="../">首页</a></li>
                <li><a href="../w3cnote">笔记首页</a></li>
                <li><a href="../w3cnote/android-tutorial-intro.html" title="Android 基础入门教程">Android</a></li>
                <li><a href="../w3cnote/es6-tutorial.html" title="ES6 教程">ES6 教程</a></li>
                <li><a href="../w3cnote/ten-sorting-algorithm.html" title="排序算法">排序算法</a></li>
                <li><a href="../w3cnote/hadoop-tutorial.html" title="Hadoop 教程">Hadoop</a></li>
                <li><a href="../w3cnote/zookeeper-tutorial.html" title="Zookeeper 教程">Zookeeper</a></li>
                <li><a href="../w3cnote/verilog-tutorial.html" title="Verilog 教程">Verilog</a></li>
                <li><a href="../w3cnote_genre/code" title="编程技术">编程技术</a></li> 
                <li><a href="../w3cnote_genre/coderlife" title="程序员人生">程序员人生</a></li>
                
                <!--<li><a href="javascript:;" class="runoob-pop">登录</a></li>
                
                
                        <li>
                <a style="font-weight:bold;" href="../linux/linux-tutorial.html#yunserver" target="_blank" onclick="_hmt.push(['_trackEvent', 'aliyun', 'click', 'aliyun'])" title="kkb">云服务器</a>
                </li>
                <li><a href="http://gk.link/a/104mQ" target="_blank" style="font-weight: bold;"onclick="_hmt.push(['_trackEvent', '极客时间', 'click', 'jike'])" title="我的圈子">极客时间</a></li>
            
                
                <li><a target="_blank" href="../shoppinglist" rel="nofollow">知识店铺</a></li> 
        -->
            </ul>
                        
              
            <ul class="mobile-nav">
                <li><a href="../w3cnote">首页</a></li>
                <li><a href="../w3cnote_genre/android" target="_blank" title="Android 基础入门教程">Android</a></li>
                <li><a href="../w3cnote/es6-tutorial.html" target="_blank" title="ES6 教程">ES6</a></li>
                <li><a href="../w3cnote_genre/joke" target="_blank" title="程序员笑话">逗乐</a></li>
                
                <a href="javascript:void(0)" class="search-reveal">Search</a> 
            </ul>
            
        </div>
    </div>
</div>


<!--  内容  -->
<div class="container main">
	<div class="row">

		<!--  Android 基础入门教程 start  -->
	<div class="col left-column" style="display:none;">
		<div class="tab">Zookeeper 教程</div>
		<div class="sidebar-box gallery-list">
			<div class="design" id="leftcolumn">  
			</div> 
		</div> 
	</div>
	<!--  Android 基础入门教程 end  -->
		<div class="col middle-column big-middle-column">
	 			<div class="article">
			<div class="article-heading">
				<h2>7.0 Zookeeper 客户端基础命令使用</h2>				<h3><em>分类</em> <a href="../w3cnote_genre/zookeeper" title="Zookeeper 教程" >Zookeeper 教程</a> </h3>
			</div>
			<div class="article-body note-body">
				<div class="article-intro">
					<p>zookeeper 命令用于在 zookeeper 服务上执行操作。</p><p>首先执行命令，打开新的 session 会话，进入终端。</p>
<pre>$ sh zkCli.sh</pre><p>
下面开始讲解基本常用命令使用，其中 acl 权限内容在后面章节详细阐述。</p>
<h3>ls 命令</h3>
<p>ls 命令用于查看某个路径下目录列表。</p>
<p>格式：</p><pre>ls path</pre>
<ul><li>
<strong>path</strong>：代表路径。
</li></ul>
以下实例查看 <strong>/runoob</strong> 节点：
<pre>$ ls /runoob</pre>
<p><img decoding="async" src="https://www.runoob.com/wp-content/uploads/2020/09/bs-command-01.png"></p>

<h3>ls2 命令</h3>
<p>ls2 命令用于查看某个路径下目录列表，它比 ls 命令列出更多的详细信息。</p>
<p>格式：</p><pre>ls2 path</pre>
<ul><li>
<strong>path</strong>：代表路径。
</li></ul>
以下实例查看 <strong>/runoob</strong> 节点：
<pre>$ ls2 /runoob</pre>
<p><img decoding="async" src="https://www.runoob.com/wp-content/uploads/2020/09/bs-command-02.png"></p>

<h3>get 命令</h3>
<p>get 命令用于获取节点数据和状态信息。</p>
<p>格式：</p><pre>get path [watch]</pre>
<ul>
<li>
<strong>path</strong>：代表路径。
</li>
<li>
<strong>[watch]</strong>：对节点进行事件监听。
</li>

</ul><p>
以下实例查看同时开启两个终端。</p>
<p>终端一:</p>
<pre>$ get /runoob watch</pre>
<p><img decoding="async" src="https://www.runoob.com/wp-content/uploads/2020/09/bs-command-03.png"></p>
<p>在终端二对此节点进行修改：</p>
<pre>$ set /runoob 1</pre>
<p><img decoding="async" src="https://www.runoob.com/wp-content/uploads/2020/09/bs-command-04.png"></p>
<p>终端一自动显示 NodeDataChanged 事件：</p>
<p><img decoding="async" src="https://www.runoob.com/wp-content/uploads/2020/09/bs-command-05.png"></p>

<h3>stat 命令</h3> 
<p>stat 命令用于查看节点状态信息。</p>
<p>格式：</p><pre>stat path [watch]</pre>
<ul>
<li>
<strong>path</strong>：代表路径。
</li>
<li>
<strong>[watch]</strong>：对节点进行事件监听。
</li>

</ul>

<p>以下实例查看 <strong>/runoob</strong> 节点状态：</p>
<pre>$ stat /runoob</pre>
<p><img decoding="async" src="https://www.runoob.com/wp-content/uploads/2020/09/bs-command-06.png"></p>


<h3>create 命令</h3> 
<p>create 命令用于创建节点并赋值。</p>
<p>格式：</p><pre>create [-s] [-e] path data acl</pre>
<ul>
<li>
<strong>[-s] [-e]</strong>：-s 和 -e 都是可选的，-s 代表顺序节点，
 -e 代表临时节点，注意其中 -s 和 -e 可以同时使用的，并且临时节点不能再创建子节点。
</li>
<li>
<strong>path</strong>：指定要创建节点的路径，比如 <strong>/runoob</strong>。
</li>
<li>
<strong>data</strong>：要在此节点存储的数据。
</li>
<li>
<strong>acl</strong>：访问权限相关，默认是 world，相当于全世界都能访问。
</li>
</ul>

<p>以下实例添加临时顺序节点：</p>
<pre>$ create -s -e /runoob 0</pre>
<p><img decoding="async" src="https://www.runoob.com/wp-content/uploads/2020/09/bs-command-07.png"></p>
<p>创建的节点既是有序，又是临时节点。</p>



<h3>set 命令</h3> 
<p>set 命令用于修改节点存储的数据。</p>
<p>格式：</p><pre>set path data [version]</pre>
<ul>
<li>
<strong>path</strong>：节点路径。
</li>
<li>
<strong>data</strong>：需要存储的数据。
</li>
<li>
<strong>[version]</strong>：可选项，版本号(可用作乐观锁)。
</li>
</ul>

<p>以下实例开启两个终端，也可以在同一终端操作：</p>
<pre>$ get /runoob</pre>
<p><img decoding="async" src="https://www.runoob.com/wp-content/uploads/2020/09/bs-command-08.png"></p>
<p>下图可见，只有正确的版本号才能设置成功：</p>
<pre>$ set /runoob 0 1
$ set /runoob 0 2
$ set /runoob 0 10
$ set /runoob 0 6</pre>
<p><img decoding="async" src="https://www.runoob.com/wp-content/uploads/2020/09/bs-command-09.png"></p>


<h3>delete 命令</h3> 
<p>delete 命令用于删除某节点。</p>
<p>格式：</p><pre>delete path [version]</pre>
<ul>
<li>
<strong>path</strong>：节点路径。
</li>
<li>
<strong>[version]</strong>：可选项，版本号（同 set 命令）。
</li>

</ul>

<p>以下实例删除 <strong>/runoob</strong> 节点的子节点：</p>
<pre>
$ ls /runoob
$ delete /runoob/child
$ get /runoob/child
</pre>
<p><img decoding="async" src="https://www.runoob.com/wp-content/uploads/2020/09/bs-command-10.png"></p>

				</div>
			</div>
			<div class="previous-next-links">
			<div class="previous-design-link">← <a href="../w3cnote/zookeeper-session.html" rel="prev"> 6.0 Zookeeper session 基本原理</a> </div>
			<div class="next-design-link"><a href="../w3cnote/zookeeper-sc-4lw.html" rel="next"> 8.0 Zookeeper 四字命令</a> →</div>
			</div>
						<div class="article-heading-ad" id="w3cnote-ad728">
			<script async src=""></script>
			<!-- 移动版 自动调整 -->
			<ins class="adsbygoogle"
			     style="display:inline-block;min-width:300px;max-width:970px;width:100%;height:90px"
			     data-ad-client="ca-pub-5751451760833794"
			     data-ad-slot="1691338467"
			     data-ad-format="horizontal"></ins>
			<script>
			(adsbygoogle = window.adsbygoogle || []).push({});
			</script>
			</div>
			<style>
@media screen and (max-width: 768px) {
	#w3cnote-ad728 {
		display: none;
	}
}
p.note-author {
    border-bottom: 1px solid #ddd;
    font-size: 18px;
    font-weight: bold;
    color: #78a15a;
    padding-bottom: 2px;
    margin-bottom: 4px;
}
</style>
<script>
var aid = 22775;
</script>
	</div>
		
	</div>
	<div class="listcol last right-column">

	<script type="text/javascript">
jQuery(document).ready(function ($){
	var total = $(".membership li").length;
	var left_list = '';
	href = window.location.href;
	
	$(".membership li").each(function(index, value){

		left_list += $(this).html();

		cur_href = $(this).find("a").attr("href");
		cur_obj = $(this);
		
		if(href.match(cur_href) != null) {
			if(index==0) {
				$(".previous-design-link").hide();
			}
			if(index==(total-1)) {
				$(".next-design-link").hide();
			}
			prev_href = cur_obj.prev("li").find("a").attr("href");
			prev_title = cur_obj.prev("li").find("a").attr("title");

			next_href = cur_obj.next("li").find("a").attr("href");
			next_title = cur_obj.next("li").find("a").attr("title");
			if(prev_title) {
				$(".previous-design-link a").attr("href", prev_href);
				$(".previous-design-link a").attr("title", prev_title);
				$(".previous-design-link a").text(prev_title);
			} else {
				$(".previous-design-link").html("");
			}

			if(next_title) {
				$(".next-design-link a").attr("href", next_href);
				$(".next-design-link a").attr("title", next_title);
				$(".next-design-link a").text(next_title);
			} else {
				$(".next-design-link").html("");
			}
		}
	});

	$("#leftcolumn").html(left_list);
});
	</script>
	<div class="sidebar-box cate-list">
	<div class="sidebar-box recommend-here list-link">
	<a href="javascript:void(0);">Zookeeper 教程</a>	</div>
	
	<ul class="membership">
		
	<li><a target="_top" data-id="22726" title="1.0 Zookeeper 教程" href="../w3cnote/zookeeper-tutorial.html" >1.0 Zookeeper 教程</a></li>
	
		
	<li><a target="_top" data-id="22725" title="2.0 Zookeeper 安装配置" href="../w3cnote/zookeeper-setup.html" >2.0 Zookeeper 安装配置</a></li>
	
		
	<li><a target="_top" data-id="22745" title="3.0 Zookeeper  linux 服务端集群搭建步骤" href="../w3cnote/zookeeper-linux-cluster.html" >3.0 Zookeeper  linux 服务端集群搭建步骤</a></li>
	
		
	<li><a target="_top" data-id="22757" title="4.0 Zookeeper Java 客户端搭建" href="../w3cnote/zookeeper-java-setup.html" >4.0 Zookeeper Java 客户端搭建</a></li>
	
		
	<li><a target="_top" data-id="22764" title="5.0 ZooKeeper 数据模型 znode 结构详解" href="../w3cnote/zookeeper-znode-data-model.html" >5.0 ZooKeeper 数据模型 znode 结构详解</a></li>
	
		
	<li><a target="_top" data-id="22770" title="6.0 Zookeeper session 基本原理" href="../w3cnote/zookeeper-session.html" >6.0 Zookeeper session 基本原理</a></li>
	
		<li>
	7.0 Zookeeper 客户端基础命令使用	</li>
	
		
	<li><a target="_top" data-id="22803" title="8.0 Zookeeper 四字命令" href="../w3cnote/zookeeper-sc-4lw.html" >8.0 Zookeeper 四字命令</a></li>
	
		
	<li><a target="_top" data-id="22810" title="9.0 Zookeeper 节点特性" href="../w3cnote/zookeeper-node-feature.html" >9.0 Zookeeper 节点特性</a></li>
	
		
	<li><a target="_top" data-id="22819" title="10.0 Zookeeper 权限控制 ACL" href="../w3cnote/zookeeper-acl.html" >10.0 Zookeeper 权限控制 ACL</a></li>
	
		
	<li><a target="_top" data-id="22824" title="11.0 Zookeeper watcher 事件机制原理剖析" href="../w3cnote/zookeeper-watcher.html" >11.0 Zookeeper watcher 事件机制原理剖析</a></li>
	
		
	<li><a target="_top" data-id="22841" title="12.0 Zookeeper 数据同步流程" href="../w3cnote/zookeeper-data-sync.html" >12.0 Zookeeper 数据同步流程</a></li>
	
		
	<li><a target="_top" data-id="22843" title="13.0 Zookeeper Leader 选举原理" href="../w3cnote/zookeeper-leader.html" >13.0 Zookeeper Leader 选举原理</a></li>
	
		
	<li><a target="_top" data-id="22845" title="14.0 Zookeeper 分布式锁实现原理" href="../w3cnote/zookeeper-locks.html" >14.0 Zookeeper 分布式锁实现原理</a></li>
	
	</ul></div>	</div>
</div>


<!-- 底部 -->
<div id="footer" class="mar-t50">
   <div class="runoob-block">
    <div class="runoob cf">
     <dl>
      <dt>
       在线实例
      </dt>
      <dd>
       &middot;<a target="_blank" href="../html/html-examples.html">HTML 实例</a>
      </dd>
      <dd>
       &middot;<a target="_blank" href="../css/css-examples.html">CSS 实例</a>
      </dd>
      <dd>
       &middot;<a target="_blank" href="../js/js-examples.html">JavaScript 实例</a>
      </dd>
      <dd>
       &middot;<a target="_blank" href="../ajx/ajax-examples.html">Ajax 实例</a>
      </dd>
       <dd>
       &middot;<a target="_blank" href="../jquery/jquery-examples.html">jQuery 实例</a>
      </dd>
      <dd>
       &middot;<a target="_blank" href="../xml/xml-examples.html">XML 实例</a>
      </dd>
      <dd>
       &middot;<a target="_blank" href="../java/java-examples.html">Java 实例</a>
      </dd>
     
     </dl>
     <dl>
      <dt>
      字符集&工具
      </dt>
      <dd>
       &middot; <a target="_blank" href="../charsets/html-charsets.html">HTML 字符集设置</a>
      </dd>
      <dd>
       &middot; <a target="_blank" href="../tags/html-ascii.html">HTML ASCII 字符集</a>
      </dd>
     <dd>
       &middot; <a target="_blank" href="https://c.runoob.com/front-end/6939/">JS 混淆/加密</a>
      </dd> 
      <dd>
       &middot; <a target="_blank" href="https://c.runoob.com/front-end/6232/">PNG/JPEG 图片压缩</a>
      </dd>
      <dd>
       &middot; <a target="_blank" href="../tags/html-colorpicker.html">HTML 拾色器</a>
      </dd>
      <dd>
       &middot; <a target="_blank" href="..//c.runoob.com/front-end/53">JSON 格式化工具</a>
      </dd>
      <dd>
       &middot; <a target="_blank" href="..//c.runoob.com/front-end/6680/">随机数生成器</a>
      </dd>
     </dl>
     <dl>
      <dt>
       最新更新
      </dt>
                   <dd>
       &middot;
      <a href="../matplotlib/matplotlib-imread.html" title="Matplotlib imread() 方法">Matplotlib imre...</a>
      </dd>
              <dd>
       &middot;
      <a href="../matplotlib/matplotlib-imsave.html" title="Matplotlib imsave() 方法">Matplotlib imsa...</a>
      </dd>
              <dd>
       &middot;
      <a href="../matplotlib/matplotlib-imshow.html" title="Matplotlib imshow() 方法">Matplotlib imsh...</a>
      </dd>
              <dd>
       &middot;
      <a href="../matplotlib/matplotlib-hist.html" title="Matplotlib 直方图">Matplotlib 直方图</a>
      </dd>
              <dd>
       &middot;
      <a href="../python3/python-func-object.html" title="Python object() 函数">Python object()...</a>
      </dd>
              <dd>
       &middot;
      <a href="../python3/python-ai-draw.html" title="Python AI 绘画">Python AI 绘画</a>
      </dd>
              <dd>
       &middot;
      <a href="../w3cnote/cursor-editor.html" title="神辅助 Cursor 编辑器，加入 GPT-4 让编码更轻松！">神辅助 Cursor ...</a>
      </dd>
             </dl>
     <dl>
      <dt>
       站点信息
      </dt>
      <dd>
       &middot;
       <a target="_blank" href="mailto:admin@runoob.com" rel="external nofollow">意见反馈</a>
       </dd>
      <dd>
       &middot;
      <a target="_blank" href="../disclaimer">免责声明</a>
       </dd>
      <dd>
       &middot;
       <a target="_blank" href="../aboutus">关于我们</a>
       </dd>
      <dd>
       &middot;
      <a target="_blank" href="../archives">文章归档</a>
      </dd>
    
     </dl>
    
     <div class="search-share">
      <div class="app-download">
        <div>
         <strong>关注微信</strong>
        </div>
      </div>
      <div class="share">
      <img width="128" height="128" src="/wp-content/themes/runoob/assets/images/qrcode.png" />
       </div>
     </div>
     
    </div>
   </div>
   <div class="w-1000 copyright">
     Copyright &copy; 2013-2023    <strong><a href="../" target="_blank">菜鸟教程</a></strong>&nbsp;
    <strong><a href="../" target="_blank">runoob.com</a></strong> All Rights Reserved. 备案号：<a target="_blank" rel="nofollow" href="https://beian.miit.gov.cn/">闽ICP备15012807号-1</a>
   </div>
  </div>
  <div class="fixed-btn">
    <a class="go-top" href="javascript:void(0)" title="返回顶部"> <i class="fa fa-angle-up"></i></a>
    <a class="qrcode"  href="javascript:void(0)" title="关注我们"><i class="fa fa-qrcode"></i></a>
    <a class="writer" style="display:none" href="javascript:void(0)"   title="标记/收藏"><i class="fa fa-star" aria-hidden="true"></i></a>
    <!-- qrcode modal -->
    <div id="bottom-qrcode" class="modal panel-modal hide fade in">
      <h4>微信关注</h4>
      <div class="panel-body"><img alt="微信关注" width="128" height="128" src="/wp-content/themes/runoob/assets/images/qrcode.png"></div> 
    </div>
  </div>

 <div style="display:none;">
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-84264393-2"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', 'UA-84264393-2');
</script>
<script>
var _hmt = _hmt || [];
(function() {
  var hm = document.createElement("script");
  hm.src = "https://hm.baidu.com/hm.js?3eec0b7da6548cf07db3bc477ea905ee";
  var s = document.getElementsByTagName("script")[0]; 
  s.parentNode.insertBefore(hm, s);
})();
</script>

</div>
<script>
window.jsui={
    www: 'https://www.runoob.com',
    uri: 'https://www.runoob.com/wp-content/themes/runoob'
};
</script>

<script src=""></script>
<script src=""></script>

</body>
</html>